/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.ajz.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.ajz.entity.AjzRecord;
import com.jeesite.modules.ajz.service.AjzRecordService;

/**
 * 检查记录Controller
 * @author cww
 * @version 2019-01-11
 */
@Controller
@RequestMapping(value = "${adminPath}/ajz/ajzRecord")
public class AjzRecordController extends BaseController {

	@Autowired
	private AjzRecordService ajzRecordService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public AjzRecord get(String id, boolean isNewRecord) {
		return ajzRecordService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("ajz:ajzRecord:view")
	@RequestMapping(value = {"list", ""})
	public String list(AjzRecord ajzRecord, Model model) {
		model.addAttribute("ajzRecord", ajzRecord);
		return "modules/ajz/ajzRecordList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("ajz:ajzRecord:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<AjzRecord> listData(AjzRecord ajzRecord, HttpServletRequest request, HttpServletResponse response) {
		ajzRecord.setPage(new Page<>(request, response));
		Page<AjzRecord> page = ajzRecordService.findPage(ajzRecord); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("ajz:ajzRecord:view")
	@RequestMapping(value = "form")
	public String form(AjzRecord ajzRecord, Model model) {
		model.addAttribute("ajzRecord", ajzRecord);
		return "modules/ajz/ajzRecordForm";
	}

	/**
	 * 保存检查记录
	 */
	@RequiresPermissions("ajz:ajzRecord:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated AjzRecord ajzRecord) {
		ajzRecordService.save(ajzRecord);
		return renderResult(Global.TRUE, text("保存检查记录成功！"));
	}
	
	/**
	 * 停用检查记录
	 */
	@RequiresPermissions("ajz:ajzRecord:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(AjzRecord ajzRecord) {
		ajzRecord.setStatus(AjzRecord.STATUS_DISABLE);
		ajzRecordService.updateStatus(ajzRecord);
		return renderResult(Global.TRUE, text("停用检查记录成功"));
	}
	
	/**
	 * 启用检查记录
	 */
	@RequiresPermissions("ajz:ajzRecord:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(AjzRecord ajzRecord) {
		ajzRecord.setStatus(AjzRecord.STATUS_NORMAL);
		ajzRecordService.updateStatus(ajzRecord);
		return renderResult(Global.TRUE, text("启用检查记录成功"));
	}
	
	/**
	 * 删除检查记录
	 */
	@RequiresPermissions("ajz:ajzRecord:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(AjzRecord ajzRecord) {
		ajzRecordService.delete(ajzRecord);
		return renderResult(Global.TRUE, text("删除检查记录成功！"));
	}
	
}